//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This is a sample for BCGControlBar Library Professional Edition
// Copyright (C) 1998-2016 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions 
// of the accompanying license agreement.
//*******************************************************************************
//
// WorkspaceBar.cpp : implementation of the CWorkspaceBar class
//

#include "stdafx.h"
#include "BCGPChartExample.h"
#include "WorkspaceBar.h"
#include "MainFrm.h"

#include "BCGPChartExampleDoc.h"
#include "BCGPChartExampleView.h"
#include "ChartElementsView.h"
#include "ChartBarView.h"
#include "ChartBar3DView.h"
#include "ChartLineView.h"
#include "ChartLine3DView.h"
#include "ChartGridView.h"
#include "CChartAreaView.h"
#include "ChartArea3DView.h"
#include "ChartPieView.h"
#include "ChartPieGroupSmallerSlicesView.h"
#include "ChartBubbleView.h"
#include "ChartCombinedView.h"
#include "ChartCombined3D.h"
#include "ChartContainerView.h"
#include "ChartHistoricalView.h"
#include "ChartHugeDataView.h"
#include "ChartHugeAverageDataView.h"
#include "ChartStockView.h"
#include "ChartStockRTView.h"
#include "ChartRealTimeView.h"
#include "ChartPointView.h"
#include "ChartLegendView.h"
#include "ChartAreaHistoricalView.h"
#include "ChartInteractiveView.h"
#include "ChartStepLineView.h"
#include "ChartPolarView.h"
#include "ChartPyramidView.h"
#include "ChartFunnelView.h"
#include "ChartBoxPlotView.h"
#include "ChartErrorBarsView.h"
#include "ChartSecondaryAxisView.h"
#include "ChartScaleBreaksView.h"
#include "ChartCustomAxisView.h"
#include "PrintChartView.h"
#include "ChartRangeBarView.h"
#include "ChartTernaryView.h"
#include "ChartObjectsView.h"
#include "ChartFormulaView.h"
#include "ChartFormulaTrendView.h"
#include "ChartVirtualSeriesView.h"
#include "ChartLogarithmicAxisView.h"
#include "ChartSurfaceView.h"
#include "ChartSurfaceAdvancedView.h"
#include "ChartVirtualView.h"
#include "ChartSmartLabelsView.h"
#include "ChartAdvancedLegendView.h"
#include "ChartThumbnailsView.h"
#include "ChartDataTableView.h"
#include "ChartMultiplePiesView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

const int idTree = 1;

/////////////////////////////////////////////////////////////////////////////
// CWorkspaceBar

BEGIN_MESSAGE_MAP(CWorkspaceBar, CBCGPDockingControlBar)
	//{{AFX_MSG_MAP(CWorkspaceBar)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_COMMAND(ID_TREE_COLLAPSE_ALL, OnTreeCollapseAll)
	ON_COMMAND(ID_TREE_EXPAND_ALL, OnTreeExpandAll)
	//}}AFX_MSG_MAP
	ON_NOTIFY(TVN_SELCHANGED, idTree, OnSelectTree)
	ON_REGISTERED_MESSAGE(BCGM_CHANGEVISUALMANAGER, OnChangeVisualManager)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWorkspaceBar construction/destruction

CWorkspaceBar::CWorkspaceBar()
{
}

CWorkspaceBar::~CWorkspaceBar()
{
}

/////////////////////////////////////////////////////////////////////////////
// CWorkspaceBar message handlers
static CDemoFeature features[] =
{
	CDemoFeature(0, CDemoFeature::BCGP_ChartElements, _T("Chart Elements"), RUNTIME_CLASS(CChartElementsView)),
	CDemoFeature(0, CDemoFeature::BCGP_ChartLegend, _T("Chart Legend"), RUNTIME_CLASS(CChartLegendView)),
	CDemoFeature(0, CDemoFeature::BCGP_ChartAdvancedLegend, _T("Chart Advanced Legend"), RUNTIME_CLASS(CChartAdvancedLegendView)),
	CDemoFeature(0, CDemoFeature::BCGP_ChartDataTable, _T("Chart Data Table"), RUNTIME_CLASS(CChartDataTableView)),
	CDemoFeature(1, CDemoFeature::BCGP_ClusteredColumn2D, _T("2D Clustered Column"), RUNTIME_CLASS(CChartBarView)),
	CDemoFeature(1, CDemoFeature::BCGP_StackedColumn2D, _T("2D Stacked Column"), RUNTIME_CLASS(CChartBarView)),
	CDemoFeature(1, CDemoFeature::BCGP_StackedColumn1002D, _T("2D 100% Stacked Column"), RUNTIME_CLASS(CChartBarView)),
	CDemoFeature(1, CDemoFeature::BCGP_StackedColumnSideBySide2D, _T("2D Side by Side Stacked Column"), RUNTIME_CLASS(CChartBarView)),
	CDemoFeature(1, CDemoFeature::BCGP_RangeColumn, _T("Range Column"), RUNTIME_CLASS(CChartRangeBarView)),
	CDemoFeature(1, CDemoFeature::BCGP_ClusteredColumn3D, _T("3D Clustered Column"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(1, CDemoFeature::BCGP_Column3D, _T("3D Column"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(1, CDemoFeature::BCGP_StackedColumn3D, _T("3D Stacked Column"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(1, CDemoFeature::BCGP_StackedColumn1003D, _T("3D 100% Stacked Column"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(1, CDemoFeature::BCGP_StackedColumnSideBySide3D, _T("3D Side by Side Stacked Column"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(1, CDemoFeature::BCGP_StackedColumnManhattan3D, _T("Manhattan Stacked Column"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(2, CDemoFeature::BCGP_Line, _T("Line"), RUNTIME_CLASS(CChartLineView)),
	CDemoFeature(2, CDemoFeature::BCGP_StackedLine, _T("Stacked Line"), RUNTIME_CLASS(CChartLineView)),
	CDemoFeature(2, CDemoFeature::BCGP_StackedLine100, _T("100% Stacked Line"), RUNTIME_CLASS(CChartLineView)),
	CDemoFeature(2, CDemoFeature::BCGP_StackedLineSpline, _T("Stacked Spline"), RUNTIME_CLASS(CChartLineView)),
	CDemoFeature(2, CDemoFeature::BCGP_StepLine, _T("Step Line"), RUNTIME_CLASS(CChartStepLineView)),
	CDemoFeature(2, CDemoFeature::BCGP_Line3D, _T("3D Line"), RUNTIME_CLASS(CChartLine3DView)),
	CDemoFeature(3, CDemoFeature::BCGP_Pie, _T("Pie"), RUNTIME_CLASS(CChartPieView)),
	CDemoFeature(3, CDemoFeature::BCGP_Pie3D, _T("Pie in 3D"), RUNTIME_CLASS(CChartPieView)),
	CDemoFeature(3, CDemoFeature::BCGP_Doughnut, _T("Doughnut"), RUNTIME_CLASS(CChartPieView)),
	CDemoFeature(3, CDemoFeature::BCGP_DoughnutNested, _T("Doughnut Nested"), RUNTIME_CLASS(CChartMultiplePiesView)),
	CDemoFeature(3, CDemoFeature::BCGP_Doughnut3D, _T("Doughnut in 3D"), RUNTIME_CLASS(CChartPieView)),
	CDemoFeature(3, CDemoFeature::BCGP_Torus3D, _T("Torus in 3D"), RUNTIME_CLASS(CChartPieView)),
	CDemoFeature(3, CDemoFeature::BCGP_PieGroupSmallerSlices, _T("Pie with Grouped Smaller Slices"), RUNTIME_CLASS(CChartPieGroupSmallerSlicesView)),
	CDemoFeature(3, CDemoFeature::BCGP_MultiplePies, _T("Multiple Pies"), RUNTIME_CLASS(CChartMultiplePiesView)),
	CDemoFeature(4, CDemoFeature::BCGP_ClusteredBar, _T("2D Clustered Bar"), RUNTIME_CLASS(CChartBarView)),
	CDemoFeature(4, CDemoFeature::BCGP_StackedBar, _T("2D Stacked Bar"), RUNTIME_CLASS(CChartBarView)),
	CDemoFeature(4, CDemoFeature::BCGP_StackedBar100, _T("2D 100% Stacked Bar"), RUNTIME_CLASS(CChartBarView)),
	CDemoFeature(4, CDemoFeature::BCGP_RangeBar, _T("Range Bar"), RUNTIME_CLASS(CChartRangeBarView)),
	CDemoFeature(4, CDemoFeature::BCGP_ClusteredBar3D, _T("3D Clustered Bar"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(4, CDemoFeature::BCGP_Bar3D, _T("3D Bar"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(4, CDemoFeature::BCGP_StackedBar3D, _T("3D Stacked Bar"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(4, CDemoFeature::BCGP_StackedBar1003D, _T("3D 100% Stacked Bar"), RUNTIME_CLASS(CChartBar3DView)),
	CDemoFeature(5, CDemoFeature::BCGP_Area, _T("Area"), RUNTIME_CLASS(CChartAreaView)),
	CDemoFeature(5, CDemoFeature::BCGP_StackedArea, _T("Stacked Area"), RUNTIME_CLASS(CChartAreaView)),
	CDemoFeature(5, CDemoFeature::BCGP_StackedArea100, _T("100% Stacked Area"), RUNTIME_CLASS(CChartAreaView)),
	CDemoFeature(5, CDemoFeature::BCGP_StackedAreaSpline, _T("Stacked Area (Spline)"), RUNTIME_CLASS(CChartAreaView)),
	CDemoFeature(5, CDemoFeature::BCGP_RangeArea, _T("Range Area"), RUNTIME_CLASS(CChartAreaView)),
	CDemoFeature(5, CDemoFeature::BCGP_StepArea, _T("Step Area"), RUNTIME_CLASS(CChartAreaView)),
	CDemoFeature(5, CDemoFeature::BCGP_HistoricalAreaSpline, _T("Historical Area (Spline)"), RUNTIME_CLASS(CChartAreaHistoricalView)),
	CDemoFeature(5, CDemoFeature::BCGP_Area3D, _T("Area in 3D"), RUNTIME_CLASS(CChartArea3DView)),
	CDemoFeature(5, CDemoFeature::BCGP_RangeArea3D, _T("Range Area in 3D"), RUNTIME_CLASS(CChartArea3DView)),
	CDemoFeature(6, CDemoFeature::BCGP_Stock, _T("Stock"), RUNTIME_CLASS(CChartStockView)),
	CDemoFeature(6, CDemoFeature::BCGP_StockRealTime, _T("Stock Real Time"), RUNTIME_CLASS(CChartStockRTView)),
	CDemoFeature(7, CDemoFeature::BCGP_Points, _T("Points (Scatter)"), RUNTIME_CLASS(CChartPointView)),
	CDemoFeature(7, CDemoFeature::BCGP_Bubble, _T("Bubble"), RUNTIME_CLASS(CChartBubbleView)),
	CDemoFeature(7, CDemoFeature::BCGP_Bubble3D, _T("Bubble with 3D Effect"), RUNTIME_CLASS(CChartBubbleView)),
	CDemoFeature(8, CDemoFeature::BCGP_Polar, _T("Polar"), RUNTIME_CLASS(CChartPolarView)),
	CDemoFeature(8, CDemoFeature::BCGP_Radar, _T("Radar"), RUNTIME_CLASS(CChartPolarView)),
	CDemoFeature(9, CDemoFeature::BCGP_Pyramid, _T("Pyramid"), RUNTIME_CLASS(CChartPyramidView)),
	CDemoFeature(9, CDemoFeature::BCGP_Pyramid3D, _T("Pyramid in 3D"), RUNTIME_CLASS(CChartPyramidView)),
	CDemoFeature(10, CDemoFeature::BCGP_Funnel, _T("Funnel"), RUNTIME_CLASS(CChartFunnelView)),
	CDemoFeature(10, CDemoFeature::BCGP_Funnel3D, _T("Funnel in 3D"), RUNTIME_CLASS(CChartFunnelView)),
	CDemoFeature(11, CDemoFeature::BCGP_BoxPlot, _T("Box Plot"), RUNTIME_CLASS(CChartBoxPlotView)),
	CDemoFeature(11, CDemoFeature::BCGP_BoxPlotNotched, _T("Box Plot with Notches"), RUNTIME_CLASS(CChartBoxPlotNotchView)),
	CDemoFeature(11, CDemoFeature::BCGP_ErrorBars, _T("Error Bars"), RUNTIME_CLASS(CChartErrorBarsView)),
	CDemoFeature(12, CDemoFeature::BCGP_Surface3DBasic, _T("Surface in 3D Basic"), RUNTIME_CLASS(CChartSurfaceView)),
	CDemoFeature(12, CDemoFeature::BCGP_Surface3DIntersect, _T("Intersected Surfaces"), RUNTIME_CLASS(CChartSurfaceView)),
	CDemoFeature(12, CDemoFeature::BCGP_Surface3DAdvanced, _T("Surface in 3D Advanced"), RUNTIME_CLASS(CChartSurfaceAdvancedView)),
	CDemoFeature(13, CDemoFeature::BCGP_HugeData, _T("Huge Data"), RUNTIME_CLASS(CChartHugeDataView)),
	CDemoFeature(13, CDemoFeature::BCGP_HugeAverageData, _T("Huge Average Data"), RUNTIME_CLASS(CChartHugeAverageDataView)),
	CDemoFeature(13, CDemoFeature::BCGP_Virtual, _T("Virtual Chart"), RUNTIME_CLASS(CChartVirtualView)),
	CDemoFeature(13, CDemoFeature::BCGP_Historical, _T("Historical"), RUNTIME_CLASS(CChartHistoricalView)),
	CDemoFeature(13, CDemoFeature::BCGP_RealTime, _T("Real Time"), RUNTIME_CLASS(CChartRealTimeView)),
	CDemoFeature(14, CDemoFeature::BCGP_TernaryBasic, _T("Ternary Basic"), RUNTIME_CLASS(CChartTernaryView)),
	CDemoFeature(14, CDemoFeature::BCGP_TernaryAdvanced, _T("Ternary Advanced"), RUNTIME_CLASS(CChartTernaryView)),
	CDemoFeature(15, CDemoFeature::BCGP_FormulaTransition, _T("Transition Formula"), RUNTIME_CLASS(CChartFormulaView)),
	CDemoFeature(15, CDemoFeature::BCGP_FormulaTrend, _T("Trend Formula"), RUNTIME_CLASS(CChartFormulaTrendView)),
	CDemoFeature(16, CDemoFeature::BCGP_CombinedCharts, _T("Combined Charts"), RUNTIME_CLASS(CChartCombinedView)),
	CDemoFeature(16, CDemoFeature::BCGP_CombinedCharts3D, _T("Combined Charts in 3D"), RUNTIME_CLASS(CChartCombined3DView)),
	CDemoFeature(16, CDemoFeature::BCGP_MultiCharts, _T("Charts Container"), RUNTIME_CLASS(CChartContainerView)),
	CDemoFeature(16, CDemoFeature::BCGP_VirtualSeries, _T("Virtual Series"), RUNTIME_CLASS(CChartVirtualSeriesView)),
	CDemoFeature(16, CDemoFeature::BCGP_SecondaryAxis, _T("Secondary Axis"), RUNTIME_CLASS(CChartSecondaryAxisView)),
	CDemoFeature(16, CDemoFeature::BCGP_SmartLabels, _T("Smart Data Labels"), RUNTIME_CLASS(CChartSmartLabelsView)),
	CDemoFeature(16, CDemoFeature::BCGP_ScaleBreaks, _T("Scale Breaks"), RUNTIME_CLASS(CChartScaleBreaksView)),
	CDemoFeature(16, CDemoFeature::BCGP_LogarithmicAxis, _T("Logarithmic Axis"), RUNTIME_CLASS(CChartLogarithmicAxisView)),
	CDemoFeature(16, CDemoFeature::BCGP_CustomAxis, _T("Custom Axis"), RUNTIME_CLASS(CChartCustomAxisView)),
	CDemoFeature(16, CDemoFeature::BCGP_ChartObjects, _T("Chart Objects and Effects"), RUNTIME_CLASS(CChartObjectsView)),
	CDemoFeature(16, CDemoFeature::BCGP_InteractiveChart, _T("Interactive Chart"), RUNTIME_CLASS(CChartInteractiveView)),
	CDemoFeature(16, CDemoFeature::BCGP_ChartAndGrid, _T("Chart and Grid"), RUNTIME_CLASS(CChartGridView)),
	CDemoFeature(16, CDemoFeature::BCGP_ChartView, _T("CBCGPChartView"), RUNTIME_CLASS(CPrintChartView)),
	CDemoFeature(16, CDemoFeature::BCGP_ChartThumbnails, _T("Chart Thumbnails"), RUNTIME_CLASS(CChartThumbnailsView)),
	CDemoFeature()
};

int CWorkspaceBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CBCGPDockingControlBar::OnCreate(lpCreateStruct) == -1)
		return -1;

	ModifyStyle(0, WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
	
	CRect rectDummy;
	rectDummy.SetRectEmpty ();

	// Create toolbar:
#ifdef _BCGSUITE_INC_
	if (!m_wndToolBar.Create (this, AFX_DEFAULT_TOOLBAR_STYLE, AFX_IDW_DIALOGBAR + 1) ||
		!m_wndToolBar.LoadToolBar(IDR_TOOLBAR_TREE, 0, 0, TRUE /* Is locked */))
	{
		TRACE0("Failed to create toolbar\n");
		return -1; // fail to create
	}

	m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY);
		
	m_wndToolBar.SetPaneStyle (
		m_wndToolBar.GetPaneStyle () & 
			~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
#else
	if (!m_wndToolBar.Create (this, dwDefaultToolbarStyle, AFX_IDW_DIALOGBAR + 1) ||
		!m_wndToolBar.LoadToolBar(IDR_TOOLBAR_TREE, 0, 0, TRUE /* Is locked */))
	{
		TRACE0("Failed to create toolbar\n");
		return -1; // fail to create
	}

	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY);
		
	m_wndToolBar.SetBarStyle (
		m_wndToolBar.GetBarStyle () & 
			~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
#endif

	m_wndToolBar.SetOwner (this);

	m_wndToolBar.SetToolBarBtnText (m_wndToolBar.CommandToIndex (ID_TREE_EXPAND_ALL), NULL, TRUE, FALSE);
	m_wndToolBar.SetToolBarBtnText (m_wndToolBar.CommandToIndex (ID_TREE_COLLAPSE_ALL), NULL, TRUE, FALSE);

	// All commands will be routed via this control, not via the parent frame:
	m_wndToolBar.SetRouteCommandsViaFrame (FALSE);

	// Create tree window:
	m_wndTree.m_bVisualManagerStyle = TRUE;
	const DWORD dwViewStyle =	WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_TRACKSELECT |
								TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_FULLROWSELECT;
	
	if (!m_wndTree.Create (dwViewStyle, rectDummy, this, idTree))
	{
		TRACE0("Failed to create workspace view\n");
		return -1;      // fail to create
	}

#ifndef _BCGSUITE_INC_
	globalData.SetWindowTheme(&m_wndTree, L"explorer", NULL);
#endif

	AddFeatureGroup(_T("Overview"), 0);
	AddFeatureGroup(_T("Column Charts"), 1);
	AddFeatureGroup(_T("Line Charts"), 2);
	AddFeatureGroup(_T("Pie Charts"), 3);
	AddFeatureGroup(_T("Bar Charts"), 4);
	AddFeatureGroup(_T("Area Charts"), 5);
	AddFeatureGroup(_T("Stock Charts"), 6);
	AddFeatureGroup(_T("X Y (Scatter) Charts"), 7);
	AddFeatureGroup(_T("Polar Charts"), 8);
	AddFeatureGroup(_T("Pyramid Charts"), 9);
	AddFeatureGroup(_T("Funnel Charts"), 10);
	AddFeatureGroup(_T("Statistical Charts"), 11);
	AddFeatureGroup(_T("Surface Charts"), 12);
	AddFeatureGroup(_T("Large Volume Charts"), 13);
	AddFeatureGroup(_T("Ternary Charts"), 14);
	AddFeatureGroup(_T("Chart Formulas"), 15);
	AddFeatureGroup(_T("Advanced Features"), 16);

	SelectItem(1);
	return 0;
}

void CWorkspaceBar::AddFeatureGroup(LPCTSTR lpszName, int nGroupID)
{
	HTREEITEM hFolder = m_wndTree.InsertItem (lpszName, 0);

	for (int i = 0;; i++)
	{
		CDemoFeature& feature = features[i];
		if (feature.m_nGroup == -1)
		{
			break;
		}

		if (feature.m_nGroup == nGroupID)
		{
			HTREEITEM hTreeItem = m_wndTree.InsertItem (feature.m_strName, 1, 1, hFolder);

			int id = GetFeatureCount() + 1;

			feature.m_id = id;
			feature.m_hItem = hTreeItem;

			m_mapItems.SetAt(id, &feature);

			m_wndTree.SetItemData(hTreeItem, id);
		}
	}
}

void CWorkspaceBar::OnSize(UINT nType, int cx, int cy) 
{
	CBCGPDockingControlBar::OnSize(nType, cx, cy);
	AdjustLayout ();

	CMainFrame* pFrame = DYNAMIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
	if (pFrame != NULL)
	{	
		pFrame->AdjustDockingLayout ();
	}
}

void CWorkspaceBar::OnSelectTree(NMHDR* /*pNMHDR*/, LRESULT* pResult) 
{
	HTREEITEM hTreeItem = m_wndTree.GetSelectedItem ();
	if (hTreeItem != NULL)
	{
		int nView = (int)m_wndTree.GetItemData(hTreeItem);
		if (nView == 0)	// Group
		{
			m_wndTree.Expand(hTreeItem, TVE_EXPAND);

			HTREEITEM hTreeChild = m_wndTree.GetNextItem(hTreeItem, TVGN_CHILD);
			if (hTreeChild != NULL)
			{
				m_wndTree.SelectItem(hTreeChild);
				nView = (int)m_wndTree.GetItemData(hTreeChild);
			}
		}

		if (nView > 0 && AfxGetMainWnd() != NULL)
		{
			((CMainFrame*)AfxGetMainWnd())->SelectView(nView);
		}
	}
	
	*pResult = 0;
}

void CWorkspaceBar::SelectItem(int id)
{
	CDemoFeature* pItem = NULL;
	
	if (m_mapItems.Lookup(id, pItem))
	{
		m_wndTree.SelectItem(pItem->m_hItem);
		m_wndTree.Expand(m_wndTree.GetParentItem(pItem->m_hItem), TVE_EXPAND);
		m_wndTree.EnsureVisible(pItem->m_hItem);
	}
}

CRuntimeClass* CWorkspaceBar::GetFeatureViewRTI(int id) const
{
	CDemoFeature* pItem = NULL;
	
	if (m_mapItems.Lookup(id, pItem))
	{
		return pItem->m_RTI;
	}

	return NULL;
}

void CWorkspaceBar::GetFeatureName(int id, CString& strTitle) const
{
	CDemoFeature* pItem = NULL;
	
	if (m_mapItems.Lookup(id, pItem))
	{
		strTitle = pItem->m_strName;
	}
	else
	{
		strTitle.Empty();
	}
}

CDemoFeature::Feature CWorkspaceBar::GetFeature(int id) const
{
	CDemoFeature* pItem = NULL;
	
	if (m_mapItems.Lookup(id, pItem))
	{
		return pItem->m_Feature;
	}
	else
	{
		return CDemoFeature::BCGP_Unknown;
	}
}

void CWorkspaceBar::AdjustLayout ()
{
	CRect rectClient;
	GetClientRect (rectClient);

	int cyTlb = m_wndToolBar.CalcFixedLayout (FALSE, TRUE).cy;

	m_wndToolBar.SetWindowPos (NULL, 0, 0, 
								rectClient.Width (), cyTlb,
								SWP_NOACTIVATE | SWP_NOZORDER);

	m_wndTree.SetWindowPos (NULL, 0, cyTlb, 
							rectClient.Width (), rectClient.Height () - cyTlb, 
							SWP_NOACTIVATE | SWP_NOZORDER);
}

void CWorkspaceToolBar::AdjustLayout ()
{
	CBCGPToolBar::AdjustLayout ();

	((CWorkspaceBar*) GetParent ())->AdjustLayout ();
}

void CWorkspaceBar::OnTreeCollapseAll() 
{
	HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
	HTREEITEM hChildItem = m_wndTree.GetRootItem();

	while (hChildItem != NULL)
	{
		m_wndTree.Expand(hChildItem, TVE_COLLAPSE);
		hChildItem = m_wndTree.GetNextItem(hChildItem, TVGN_NEXT);
	}

	m_wndTree.Expand(m_wndTree.GetParentItem(hSelectedItem), TVE_EXPAND);
	m_wndTree.SelectItem(hSelectedItem);
	m_wndTree.EnsureVisible(hSelectedItem);
}

void CWorkspaceBar::OnTreeExpandAll() 
{
	HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
	HTREEITEM hChildItem = m_wndTree.GetRootItem();

	while (hChildItem != NULL)
	{
		m_wndTree.Expand(hChildItem, TVE_EXPAND);
		hChildItem = m_wndTree.GetNextItem(hChildItem, TVGN_NEXT);
	}

	m_wndTree.EnsureVisible(hSelectedItem);
}

LRESULT CWorkspaceBar::OnChangeVisualManager (WPARAM wp, LPARAM lp)
{
	LRESULT lRes = 0;

#ifndef _BCGSUITE_INC_
	CMainFrame* pFrame = DYNAMIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
	if (pFrame != NULL)
	{
		if (pFrame->IsDarkTheme())
		{
			globalData.SetWindowTheme(&m_wndTree, NULL, NULL);
		}
		else
		{
			globalData.SetWindowTheme(&m_wndTree, L"explorer", NULL);
		}
	}

	lRes = CBCGPDockingControlBar::OnChangeVisualManager(wp, lp);
#else
	UNREFERENCED_PARAMETER(wp);
	UNREFERENCED_PARAMETER(lp);
#endif

	return lRes;
}
